#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<iostream>
using namespace std;
int global_value=100;
void* startRoutine(void* args)
{
    pthread_detach(pthread_self());
    cout<<"线程分离————"<<endl;
    while(true)
    {
        cout<<"thread: "<<pthread_self()<<"global_value:"<<global_value
        <<"&global_value:"<<&global_value<<"Inc: "<< global_value++<<endl;
        sleep(1);
    }
}
int main()
{
    pthread_t tid1;
    pthread_t tid2;
    pthread_t tid3;
    pthread_create(&tid1,nullptr,startRoutine,(void*)"thread 1");
    pthread_create(&tid2,nullptr,startRoutine,(void*)"thread 2");
    pthread_create(&tid3,nullptr,startRoutine,(void*)"thread 3");
    
    sleep(1);
    int n=pthread_join(tid1,nullptr);
    cout<<n<<":"<<strerror(n)<<endl;
    n=pthread_join(tid2,nullptr);
    cout<<n<<":"<<strerror(n)<<endl;
    n=pthread_join(tid3,nullptr);
    cout<<n<<":"<<strerror(n)<<endl;
    return 0;
}